
import {reqCategoryList,reqBannerList,reqFloorList} from '@/api/index.js'


const home = {
    namespaced: true,  // 开启命名空间
    state: {
        categoryList: [],
        bannerList: [],
        floorList: [],
    },
    mutations:{
        RECEIVE_CATEGORYLIST(state,categoryList){
            state.categoryList = categoryList
        },
        RECEIVE_BANNERLIST(state,bannerList){
            state.bannerList = bannerList
        },
        RECEIVE_FLOORLIST(state,floorList){
            state.floorList = floorList
        },
    },
    actions: {
            // 发请求
            // await和async 代码实现异步效果  可读性强
            async getCategoryList({commit}){
                const result = await reqCategoryList()
                if(result.code === 200){
                    commit('RECEIVE_CATEGORYLIST',result.data)
                }
        
            },
            async getBannerList({commit}){
                const result = await reqBannerList()
                if(result.code === 200){
                    commit('RECEIVE_BANNERLIST',result.data)
                }
            },
            async getFloorList({commit}){
                const result = await reqFloorList()
                if(result.code === 200){
                    commit('RECEIVE_FLOORLIST',result.data)
                }
            }
        },

    getters: {

    }
}

export default home
// const state = {
//     categoryList: []
// }
// const mutations = {
    
//     RECEIVE_CATEGORYLIST(state,categoryList){
//         state.categoryLsit = categoryList
//     }
// }
// const actions = {
//     // 发请求
//     // await和async 代码实现异步效果  可读性强
//     async getCategoryList({commit}){
//         const result = await reqCategoryList()
//         if(result.code === 200){
//             commit('RECEIVE_CATEGORYLIST',result.data)
//         }

//     }
// }
// const getters = {}

// export default {
//     state,
//     mutations,
//     actions,
//     getters,
// }